package com.authority.result;

import java.util.List;

public class PageResult<T> {

	// 当前页数
	private Integer index;

	// 开始位置--分页使用
	private Integer begin;

	// 记录数--分页使用
	private Integer num=15;

	// 总记录数--分页查询使用
	private int totalNum;

	// 排序字段
	private String order;

	// 返回list
	private List<T> list;
	
	//总页数
	private int totalpage;
	
	private boolean isNotAdmin = false;

	public int getTotalpage() {
		return totalpage;
	}

	public void setTotalpage(int totalpage) {
		this.totalpage = totalpage;
	}

	public Integer getIndex() {
		return index;
	}

	public void setIndex(Integer index) {
		
		if(index < 1) {
			this.index = 1;
			this.begin = 0;
		}else if(index>totalpage){
			this.index=totalpage;
			begin=num * (this.index - 1);
		}else {
			this.index = index;
			begin = num * (index - 1);
		}
		//如果查询totleRows为0的时候，startposition为负，这里进行调整
		if(begin<0){
			begin=0;
		}
	}

	public Integer getBegin() {
		return begin;
	}

	public void setBegin(Integer begin) {
		this.begin = begin;
	}

	public Integer getNum() {
		return num;
	}

	public void setNum(Integer num) {
		this.num = num;
	}

	public int getTotalNum() {
		return totalNum;
	}

	public void setTotalNum(int totalNum) {
		this.totalNum = totalNum;
		this.totalpage =totalNum%num==0?totalNum/num:totalNum/num+1;
	}

	public String getOrder() {
		return order;
	}

	public void setOrder(String order) {
		this.order = order;
	}

	public List<T> getList() {
		return list;
	}

	public void setList(List<T> list) {
		this.list = list;
	}
	
	public static <T> PageResult<T> create(List<T> list,int totalNum,int index,int num){
		return new PageResult<T>(list,totalNum,index,num);
	}
	
	public PageResult(){
	}
	
	public PageResult(List<T> list,int totalNum,int index,int num){
		this.list = list;
		this.num = num;
		setTotalNum(totalNum);
		//this.totalNum = totalNum;
		setIndex(index);
		
	}

	public boolean isNotAdmin() {
		return isNotAdmin;
	}

	public void setNotAdmin(boolean isNotAdmin) {
		this.isNotAdmin = isNotAdmin;
	}
	
}
